class Solution {
public:
    unordered_map<int, int> ma;
    vector<int> arr;
    vector<int> topKFrequent(vector<int>& nums, int k) {
        for (auto& x : nums) ma[x] += 1;
        priority_queue<pair<int, int>> que;
        for (auto& x : ma) que.push(pair<int, int>(x.second, x.first));
        for (int i = 0; i < k; i++)
        {
            arr.push_back(que.top().second);
            que.pop();
        }
        return arr;
    }
};